import {Component, OnDestroy, OnInit} from '@angular/core';
import {PageVoService} from '../../service/page-vo.service';
import {LinkDto} from '../../entity/link-dto';
import {DocIndexService} from '../../service/doc-index.service';
import {Subscription} from 'rxjs/index';


@Component({
    selector: 'app-page-index',
    templateUrl: './page-index.component.html',
    styleUrls: ['./page-index.component.css']
})
export class PageIndexComponent implements OnInit, OnDestroy {
    private docListSubscribe: Subscription;

    constructor(private pageVoService: PageVoService,
                private docIndexService: DocIndexService) {
    }

    ngOnInit() {
        const pageVo = this.pageVoService.getPageVo();
        pageVo.title = 'Duo-Doc';
        pageVo.crumbs = [
            <LinkDto>{
                text: '项目索引',
                frontIcon: 'home'
            }
        ];

        this.docListSubscribe = this.docIndexService.getDocList().subscribe(resp => {
            this.docIndexService.updateDocListMenu(resp);
        });
    }

    ngOnDestroy(): void {
        if (this.docListSubscribe) {
            this.docListSubscribe.unsubscribe();
        }
    }
}
